<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;

class CalculateSettlementTaxJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct(private readonly string $settlementId)
    {
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        try {
            Artisan::call('settlement:calculate-tax', [
                'settlement_id' => $this->settlementId,
            ]);
        } catch (\Throwable $exception) {
            Log::error('[Tax] 结算单算税任务执行失败', [
                'settlement_id' => $this->settlementId,
                'error' => $exception->getMessage(),
            ]);

            throw $exception;
        }
    }
}
